package com.example.administrator.a2048game;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView;
import android.view.ContextMenu;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

public class Number_Adapter extends RecyclerView.Adapter<Number_Adapter.ViewHolder> {

    private Context mContext;

    private List<Number> numberList;

    static class ViewHolder extends RecyclerView.ViewHolder {

        TextView number;
        CardView cardView;

        ViewHolder(View view) {
            super(view);
            number = (TextView) view.findViewById(R.id.tv_number);
            cardView = (CardView) view;
        }

    }

    public Number_Adapter(List<Number> numberList) {
        this.numberList = numberList;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        if(mContext == null) {
            mContext = viewGroup.getContext();
        }
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.number_item, viewGroup , false);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder viewHolder, int i) {

        Number number = numberList.get(i);
        String str = String.valueOf(number.getData());
        viewHolder.number.setText(str);
    }

    @Override
    public int getItemCount() {
        return numberList.size();
    }
}
